﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TSL.AjaxResult.KaiJiang
{
    public class KaiJiang6
    {
        public static int OpenJJ(string caipiao_name, string codes, string buycodes)
        {
            switch (caipiao_name)
            {
                case "直选好运特":
                    return ZhiXuanHYT(codes, buycodes);

                case "直选好运一":
                    return ZhiXuanHYY(codes, buycodes);

                case "直选好运二":
                    return ZhiXuanHYE(codes, buycodes);

                case "直选好运三":
                    return ZhiXuanHYS(codes, buycodes);

                case "直选好运四":
                    return ZhiXuanHYSi(codes, buycodes);

                case "直选好运五":
                    return ZhiXuanHYW(codes, buycodes);

                case "通选好运三":
                    return TongXuanSan(codes, buycodes);

                case "通选好运四":
                    return TongXuanSi(codes, buycodes);

                case "通选好运五":
                    return TongXuanWu(codes, buycodes);
            }
            return 0;
        }

        public static int TongXuanSan(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win >= 3)
                {
                    winbonus += (win * (win - 1)) / 6;
                }
            }
            return winbonus;
        }

        public static int TongXuanSi(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win >= 4)
                {
                    winbonus += (win * (win - 1)) / 12;
                }
            }
            return winbonus;
        }

        public static int TongXuanWu(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win == 5)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int ZhiXuanHYE(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win >= 2)
                {
                    winbonus += (win * (win - 1)) / 2;
                }
            }
            return winbonus;
        }

        public static int ZhiXuanHYS(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win >= 3)
                {
                    winbonus += (win * (win - 1)) / 6;
                }
            }
            return winbonus;
        }

        public static int ZhiXuanHYSi(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win >= 4)
                {
                    winbonus += (win * (win - 1)) / 12;
                }
            }
            return winbonus;
        }

        public static int ZhiXuanHYT(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode1 = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int win = 0;
            int winbonus = 0;
            for (int i = 0; i < mycode1.Length; i++)
            {
                win = 0;
                string[] mycode3 = mycode1[i].ToString().Trim().Split(new char[] { ',' });
                for (int j = 0; j < mycode3.Length; j++)
                {
                    _code = code[4].ToString().Trim() + " ";
                    if (((mycode3[j].ToString().Trim() + " ").IndexOf(_code) != -1) && (mycode3.Length == 2))
                    {
                        win++;
                    }
                }
                if (win == 2)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int ZhiXuanHYW(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win == 5)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int ZhiXuanHYY(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                string[] mycodes = mycode[i].Split(new char[] { ',' });
                for (int j = 0; j < mycodes.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycodes[j].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                winbonus += win;
            }
            return winbonus;
        }
    }

}
